package com.hsmpay.mobile.action.added;

import com.hsmpay.mobile.action.base.MobileBaseAction;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 增值业务 面值获得接口
 *
 * @author 颜铃璋
 */
@Controller("addedFaceValueAction")
@Scope("prototype")
public class AddedFaceValueAction extends MobileBaseAction {
    private static final long serialVersionUID = -4673661447674955051L;
    //static Logger log = Logger.getLogger(AddedFaceValueAction.class);

    /**
     * @throws Exception
     */
    public String getFace() throws Exception {
        Integer type = Integer.parseInt(getJsonString("type"));
        switch (type) {
            case 1:
                recharge();
                break;//话费充值
            case 2:
                fixed();
                break;//固话宽带充值
        }

        return null;
    }

    //1、2、5、10、20、30、50、100、300
    public void recharge() {
        String faceValue = "1,6|2,7|5,10|10,15|20,25|30,35|50,50|100,100|300,300";
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("reqCode", "0000");
        result.put("reqMsg", "获得话费充值面值成功！");
        result.put("list", jiexi(faceValue));
        sendAppMsg(result);
    }

    //固话/宽带充值
    public void fixed() {
        Integer teltype = Integer.parseInt(getJsonString("teltype"));
        String faceValue = "10,15|20,25|30,35|50,50|100,100|300,300";//默认电信
        if (teltype == 2) {//联通
            faceValue = "50,50|100,100";
        }

        Map<String, Object> result = new HashMap<String, Object>();
        result.put("reqCode", "0000");
        result.put("reqMsg", "获得话费充值面值成功！");
        result.put("list", jiexi(faceValue));
        sendAppMsg(result);
    }


    public List<Map<String, String>> jiexi(String price) {
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        String[] priceArray = price.split("\\|");
        for (String s : priceArray) {
            String[] sArray = s.split(",");
            Map<String, String> result = new HashMap<String, String>();
            result.put("faceValue", sArray[0]);
            result.put("amount", sArray[1]);//+"00"
            list.add(result);
        }
        return list;
    }

//	public static void  main(String args[]){
//		AddedFaceValueAction a = new AddedFaceValueAction();
//		a.recharge();
//	}
}
